<?php
$this->breadcrumbs = array(
    'Login' => TreTodayUrl::backendLoginUrl()
);
?>
<?php $form = $this->beginWidget('CActiveForm', array(
    'id' => 'registerForm',
    'enableClientValidation' => true,
    'method' => 'POST',
    'clientOptions' => array(
        'errorCssClass' => 'has-error',
        'validateOnSubmit' => true,
    ),
    'htmlOptions' => array(
        'role' => 'form',
        'class' => 'form-horizontal',
        'enctype' => 'multipart/form-data'
    )
)); ?>
<fieldset>
    <legend>
        <h1>Đăng kí</h1>
    </legend>
    <?php if ($model->getErrors()) {
        ?>
        <div class="alert alert-error">
            <?php echo $form->errorSummary($model); ?>
        </div>
    <?php } ?>
    <div id="content" class="register-wrapper">
        <table>
            <tr>
                <td>
                    <?php echo $form->labelEx($model, 'first_name', array('class' => 'control-label')); ?>
                </td>
                <td>
                    <?php echo $form->textField($model, 'first_name', array('class' => 'textbox')); ?>
                </td>
            </tr>
            <tr>
                <td>
                    <?php echo $form->labelEx($model, 'last_name', array('class' => 'control-label')); ?>
                </td>
                <td>
                    <?php echo $form->textField($model, 'last_name', array('class' => 'textbox')); ?>
                </td>
            </tr>
            <tr>
                <td style="width:130px">
                    <?php echo $form->labelEx($model, 'user_name', array('class' => 'control-label')); ?>
                </td>
                <td>
                    <?php echo $form->textField($model, 'user_name', array('class' => 'textbox')); ?>
                </td>
            </tr>
            <tr>
                <td><?php echo $form->labelEx($model, 'password', array('class' => 'control-label')); ?></td>
                <td> <?php echo $form->passwordField($model, 'password', array('size' => 60, 'maxlength' => 255, 'class' => 'textbox')); ?></td>
            </tr>
            <tr>
                <td><?php echo $form->labelEx($model, 'confirm_password', array('class' => 'control-label')); ?></td>
                <td> <?php echo $form->passwordField($model, 'confirm_password', array('size' => 60, 'maxlength' => 255, 'class' => 'textbox')); ?></td>
            </tr>
            <tr>
                <td>
                    <?php echo $form->labelEx($model, 'sex', array('class' => 'control-label')); ?>
                </td>
                <td>
                    <?php echo $form->radioButtonList($model, 'sex', array('0' => 'Nữ', '1' => 'Nam')); ?>
                </td>
            </tr>

            <tr>
                <td>
                    <?php echo $form->labelEx($model, 'email', array('class' => 'control-label')); ?>
                </td>
                <td>
                    <?php echo $form->textField($model, 'email', array('class' => 'textbox')); ?>
                </td>
            </tr>

            <tr>
                <td>
                    <?php echo $form->labelEx($model, 'phone', array('class' => 'control-label')); ?>
                </td>
                <td>
                    <?php echo $form->textField($model, 'phone', array('class' => 'textbox')); ?>
                </td>
            </tr>
            <tr>
                <td>
                    <?php echo $form->labelEx($model, 'yahoo', array('class' => 'control-label')); ?>
                </td>
                <td>
                    <?php echo $form->textField($model, 'yahoo', array('class' => 'textbox')); ?>
                </td>
            </tr>

            <tr>
                <td>
                    <?php echo $form->labelEx($model, 'address', array('class' => 'control-label')); ?>
                </td>
                <td>
                    <?php echo $form->textField($model, 'address', array('class' => 'textbox')); ?>
                </td>
            </tr>

            <tr>
                <td>
                    <?php echo $form->labelEx($model, 'website', array('class' => 'control-label')); ?>
                </td>
                <td>
                    <?php echo $form->textField($model, 'website', array('class' => 'textbox')); ?>
                </td>
            </tr>

            <tr class="tr-category" data-index="0">
                <td>
                    <?php echo $form->labelEx($model, 'categories', array('class' => 'control-label')); ?>
                </td>
                <td>
                    <select name="UserBack[categories][]" style="height: 25px;width: 100%" data-index="0">
                        <?php foreach ($categories as $cat) { ?>
                            <option
                                value="<?php echo $cat['cat_id'] ?>" <?php echo $cat['cat_id'] == $cat['cat_id'] ? 'selected="selected"' : "" ?>> <?php echo $cat['cat_name'] ?></option>
                        <?php } ?>
                    </select>

                </td>
            </tr>
            <tr>
                <td></td>
                <td style="text-align: right"><span style="" id="addMore" class="btn-add-more">Thêm</span></td>
            </tr>

            <tr>
                <td>
                    <?php echo $form->labelEx($model, 'avatar', array('class' => 'control-label')); ?>
                </td>
                <td>
                    <?php echo $form->fileField($model, 'image'); ?>
                </td>
            </tr>
            <tr>
                <td>
                </td>
                <td>
                    Nếu bạn đã có tài khoản click
                    <a style="font-weight: bold;font-size: 13px"
                       href="<?php echo TreTodayUrl::getLoginUrl() ?>"> Đăng nhập
                    </a>
                </td>
            </tr>
            <tr>
                <td></td>
                <td>    <?php echo CHtml::submitButton('Đăng kí', array('class' => 'btn btn-default')); ?></td>
            </tr>
        </table>
    </div>

</fieldset>

<?php $this->endWidget(); ?>
<script type="text/javascript">
    $(".register-wrapper").delegate('.btn-add-more', 'click', function () {
        var $index = $(".register-wrapper").find('.tr-category').length;
        $index = $index + 1;

        $html_wrapper = $(".register-wrapper").find('.tr-category[data-index=0]');

        $value = ($html_wrapper.html());
        $a = $($value).find('option');
        $html = '<td></td><td>';
        $html += '<select name="UserBack[categories][]" style="height: 25px;width: 100%" >';
        for (var i = 0; i < $a.length; i++) {
            $($a[i]).attr("selected", "");
            $html += "<option value='" + $($a[i]).attr("value") + "'>" + $($a[i]).html() + "</option>";
        }
        $html += '</select>';
        $html += '</td>';

        $(".register-wrapper").find('.tr-category').last().after('<tr class="tr-category" data-index ="' + $index + '">' + $html + "</tr>");
        $(".register-wrapper").find('.tr-category').last().attr('data-index', $index);
    });
</script>